﻿using ELearningSystem.Gateway.Entities;
using NHibernate;
using NHibernate.Criterion;

namespace ELearningSystem.Gateway.Gateway
{
    public class UserGateway : CommonGateway
    {
        public Learner GetLearnerUsingEmail(string email)   
        {
            using (ISession session = createDataBaseSession.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    var learner = (Learner)session.CreateCriteria(typeof(Learner)).Add(Restrictions.Eq("EmailAddress", email)).UniqueResult();
                    return learner;
                }
            }
        }

        public Learner GetLearnerWithName(string name)
        {
            using (ISession session = createDataBaseSession.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    var learner = (Learner)session.CreateCriteria(typeof(Learner)).Add(Restrictions.Eq("Name", name)).UniqueResult<Learner>();
                    return learner;
                }
            }
        }
    }
}
